Exercise: Plotting Torus

In this lesson, you will be plotting a torus.

We'll cover the following

In geometry, a torus is a surface of revolution generated by revolving a circle in three-dimensional space about an axis that is coplanar with the circle.

A torus is defined by the following equation:

x(θ,ϕ)=(R+rcosθ)cosϕx(\theta, \phi)=(R+rcos\theta)cos\phi

y(θ,ϕ)=(R+rcosθ)sinϕy(\theta, \phi)=(R+rcos\theta)sin\phi

z(θ,ϕ)=rsinθz(\theta, \phi)=rsin\theta

Courtesy: https://answers.unity.com/storage/temp/114690-parametrization-of-a-torus-by-coordinates-left-the.png
Courtesy: https://answers.unity.com/storage/temp/114690-parametrization-of-a-torus-by-coordinates-left-the.png

If you see the diagram above,

  • θ\theta and Ï•\phi are angles which make a full circle so their values start and end at the same point:
    • θ\theta is the angle inside the cross-section of the tube and is in the x−zx-z plane.
    • Ï•\phi is the angle from one point on the torus to another point through the center and it lies in the x−yx-y plane.
  • RR is the distance from the center of the tube to the center of the torus,
  • rr is the radius of the tube.

The ratio R:rR:r is usually 3:13:1 or 2:12:1.

Task#

In this exercise, you will plot tori with a different viewing axis and colormaps using surface plots.

Problem statement#

Define a function torus() with arguments r, R and angle.

torus() should return 3 arrays: x, y and z.

Plot two 3-D surface plots on the same figure with different axes. Set the values of arguments as you seem fit.

Set appropriate axis limits based on the dimensions of your torus.

Properties of First Plot

  1. colormap = cool
  2. elevation angle = 36
  3. azimuthal angle = 26

Properties of Second Plot

  1. colormap = rainbow
  2. elevation angle = 15
  3. azimuthal angle = 45

Use all the important modules needed.

A basic structure of the code is given below.


The solution to this exercise will be discussed in the next lesson.

Solution Review: Plotting Temperatures

Solution Review: Plotting Torus